import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_oa/route/routes.dart';

class Login extends StatefulWidget {
  @override
  _LoginState createState() => _LoginState();
}

class MyTextField extends StatelessWidget {
  final String hintStrig;
  final bool obscureText;
  final TextEditingController controller;

  const MyTextField(
      {Key key, this.hintStrig, this.obscureText = false, this.controller})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: TextField(
        controller: controller,
        obscureText: obscureText,
        style: TextStyle(
          fontSize: 16.0,
        ),
        keyboardType: TextInputType.phone,
        decoration: InputDecoration(
            hintText: hintStrig,
            hintStyle: TextStyle(color: Colors.black12, fontSize: 16),
            border: InputBorder.none),
//        autofocus: false,
      ),
    );
  }
}

class _LoginState extends State<Login> {
  TextEditingController _controller =
      TextEditingController.fromValue(TextEditingValue(text: ''));

  showSnackbar(BuildContext context ,String info) async {
    var snackBar = SnackBar(
      content: Text(info),
      backgroundColor: Colors.green,
    );
    Scaffold.of(context).showSnackBar(snackBar);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            SizedBox(
              height: 100,
            ),
            Icon(
              Icons.account_balance,
              size: 84,
              color: Colors.green,
            ),
            Padding(
              padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
              child: Row(
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  Icon(
                    Icons.mobile_screen_share,
                    color: Colors.black26,
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(10, 0, 15, 0),
                    color: Colors.black12,
                    height: 24,
                    width: 1,
                  ),
                  MyTextField(
                    controller: _controller,
                    hintStrig: '请输入电话号码',
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.fromLTRB(0, 5, 0, 5),
              height: 1,
              color: Colors.black12,
            ),
            Row(
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Icon(
                  Icons.lock,
                  color: Colors.black26,
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
                  color: Colors.black12,
                  height: 24,
                  width: 1,
                ),
                MyTextField(
                  hintStrig: '请输入密码',
                  obscureText: true,
                )
              ],
            ),
            Container(
              height: 1,
              color: Colors.black12,
            ),
            Padding(
              padding: const EdgeInsets.fromLTRB(0, 30, 0, 0),
              child: Row(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Text(
                    "公司注册",
                    style: TextStyle(fontSize: 16, color: Colors.green),
                  ),
                  Text(
                    "验证码登录",
                    style: TextStyle(fontSize: 16, color: Colors.green),
                  ),
                ],
              ),
            ),
            SizedBox(
              height: 30,
            ),
            //snackbar不弹出
            Builder(builder: (BuildContext context) {
              return MaterialButton(
                height: 40,
                elevation: 0,
                onPressed: () {
//                  showSnackbar(context,_controller.text);

                String route = '${Routes.main}';
                Routes.router.navigateTo(context, route,
                    replace: true, transition: TransitionType.fadeIn);
                },
                child: Text(
                  "登录",
                  style: TextStyle(color: Colors.white, fontSize: 18),
                ),
                color: Colors.green,
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(20))),
              );
            }),
          ],
        ),
      ),
    );
  }
}
